{% extends 'goods/goodbase.html' %}

{% block head %}

    <script>
        $(function () {
            var num_show = $('.num_show');
{#            $('#show_count').html(data.cart_num);#}
            num_show.blur(function () {

                {#                var num_show = num_show;#}
                var num = parseInt(num_show.val());
                {#                alert(num);#}
                if (isNaN(num)) {
                    num = 1;


                } else if (num < 1) {

                    num = 1;

                } else if (num > 5) {
                    num = 5;
                }
                {#                num.toFixed(2)#}
                num_show.val(num);
                var total = num *{{ good.gprice }};

                {#                alert(total);#}
                $('.total em').html(total.toFixed(2) + '元');

            });

            {#   加了过后再调用上面那个失去焦点的函数#}

            $('.add').click(function () {
                var num = parseInt(num_show.val());
                num++;
                num_show.val(num).blur();
            });
            $('.minus').click(function () {
                var num = parseInt(num_show.val());
                num--;
                num_show.val(num).blur();
            });


            $('#add_cart').click(function () {

                var gid = {{ good.id }};
                var nums = $('.num_show').val();

                $.post('/cart/add/', {'gid': gid, 'nums': nums}, function (data) {
                    if (data.login == 2) {
                        window.location.href = "/user/login/";
                    }
                    if (data.status == 1) {
                        alert(data.msg);
                    } else {
                        if (data.maxcount == 2) {
                            alert(data.maxcountmsg)
                        } else {


                            var $add_x = $('#add_cart').offset().top;
                            var $add_y = $('#add_cart').offset().left;

                            var $to_x = $('#show_count').offset().top;
                            var $to_y = $('#show_count').offset().left;

                            $(".add_jump").css({'left': $add_y + 80, 'top': $add_x + 10, 'display': 'block'})

                            $(".add_jump").stop().animate({
                                    'left': $to_y + 7,
                                    'top': $to_x + 7
                                },
                                "fast", function () {
                                    $(".add_jump").fadeOut('fast', function () {
                                        {#                                    alert({{ data. }})#}
                                        $('#show_count').html(data.cart_num);
{#                                        $.cookie('cart_num',data.cart_num);#}
                                    });

                                });
                        }
                    }


                });

            });


            $('#buy_btn').click(function () {
                var gid = {{ good.id }};
                var nums = $('.num_show').val();
                 $.post('/cart/add/', {'gid': gid, 'nums': nums}, function (data) {
{#                     alert('hello ')#}
                    if (data.login == 2) {
                        window.location.href = "/user/login/";
                    }
                    if (data.status == 1) {
                        alert(data.msg);
                    } else {
                        if (data.maxcount == 2) {
                            alert(data.maxcountmsg)
                        } else {

                            window.location.href = "/order/?cid=" + data.cid;


                        }
                    }


                });

            })

        })

    </script>



{% endblock head %}



{% block breadcrumb %}
    {#        这里填 全部分类 > 新鲜水果 > 商品详情  这个#}
    <div class="breadcrumb">
        <a href="/">全部分类</a>
        <span>></span>
        {#        /page/typeid/sortid/#}
        <a href="/list/1/{{ type.id }}/1/">{{ type.ttitle }}</a>
        <span>></span>
        <a href="/{{ good.id }}/">{{ good.gtitle }}</a>
    </div>
    <div class="goods_detail_con clearfix">
        <div class="goods_detail_pic fl"><img src="/static/media/{{ good.gpic }}"></div>

        <div class="goods_detail_list fr">
            <h3>{{ good.gtitle }}</h3>
            <p>{{ good.gjianjie }}</p>
            <div class="prize_bar">
                <span class="show_pirze">¥<em>{{ good.gprice }}</em></span>
                <span class="show_unit">单  位：{{ good.gunit }}</span>
            </div>
            <div class="goods_num clearfix">
                <div class="num_name fl">数 量：</div>
                <div class="num_add fl">
                    <input type="text" class="num_show fl" value="1">
                    <a href="javascript:;" class="add fr">+</a>
                    <a href="javascript:;" class="minus fr">-</a>
                </div>
            </div>
            <div class="total">总价：<em>{{ good.gprice }}元</em></div>
            <div class="operate_btn">
                <a href="javascript:;" class="buy_btn" id="buy_btn">立即购买</a>
                <a href="javascript:;" class="add_cart" id="add_cart">加入购物车</a>
            </div>
        </div>
    </div>
{% endblock breadcrumb %}







{% block r_wrap %}

    <div class="r_wrap fr clearfix">
        <ul class="detail_tab clearfix">
            <li class="active">商品介绍</li>
            <li>评论</li>
        </ul>

        <div class="tab_content">
            <dl>
                {{ good.gcontent|safe }}
            </dl>
        </div>

    </div>


    <div class="add_jump"></div>
{% endblock r_wrap %}










